import { Toast } from "antd-mobile"
import { http } from "../../utils/http"

// 获取 我的 页面 - 用户自己的信息
export const getUser = () => async (dispatch) => {
  const res = await http.get("/user")
  console.log(res.data.data)
  dispatch({ type: "GET_USER", payload: res.data.data })
}
// 获取用户自己的信息
export const getUserMsg = () => async (dispatch) => {
  const res = await http.get("/user/profile")
  dispatch({ type: "GET_USERMSG", payload: res.data.data })
}
// 上传图片
export const updatePhoto = (file) => async (dispatch) => {
  const res = await http.patch("/user/photo", file)
  dispatch({ type: "UPDATE_PHOTO", payload: res.data.data.photo })
}
// 编辑用户资料
export const updateuserMsg = (name, value) => async (dispatch) => {
  await http.patch("/user/profile", {
    [name]: value
  })
  Toast.show({
    icon: "success",
    content: "更新成功"
  })
  dispatch({ type: "UPDATE_USERMSG", payload: { name, value } })
}
//  updateNameValue
